extends Node2D


func _ready() -> void:
	home()
	pass # Replace with function body.

func home():
	var homeResource=preload("res://scene/Home.tscn")
	var home=homeResource.instantiate()
	add_child(home)
	$Home/Control/Start.pressed.connect(startGame)
	$Swoosh.play()
	if get_node_or_null("Over")!=null: #如果从over界面过来的话，要销毁over
		$Over.queue_free()
	pass
	
func startGame():
	var gameResource=preload("res://scene/Game.tscn")
	var game=gameResource.instantiate()
	add_child(game)
	
	game.end_game.connect(endGame)
	
	#切换场景，删除Home
	$Home.queue_free()
	
	$Swoosh.play()
	pass

func endGame(point:int):
	var overResource=preload("res://scene/Over.tscn")
	var over=overResource.instantiate()
	add_child(over)
	$Over/Control/Score.text=String.num_int64(point)
	$Over/Control/Menu.connect("pressed",Callable(self,"home"))
	$Game.queue_free()
	$Die.play()
	pass
